clear;close;clc;

f = figure();
% pause();

% draw mountain
t = 0.1: 0.1: 10;
[X, Y] = meshgrid(t, t);
Z = fitness(X, Y);
mesh(X, Y, Z);
hold on

% init data
t = 0.1: 0.1: 1;
[X, Y] = meshgrid(t, t);
Z = fitness(X, Y);
K = [X(:), Y(:), Z(:)];
% draw location
s = showData(K);

years = 15;
for k = 1: years
    K = ga(K, 0.1);
    delete(s);
    s = showData(K, 'g');
    title(sprintf('yser: %d, number: %d', k, length(K)));
    pause(0.1);
    
    K = naturalSelection(K);
    delete(s);
    s = showData(K, 'r');
    title(sprintf('yser: %d, number: %d', k, length(K)));
    pause(0.1);
end
